package com.suixun.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.authority.controller.BaseManager;
import com.suixun.entity.HomeModule;
import com.suixun.entity.HomeModuleConfig;
import com.suixun.service.HomeModuleConfigService;
import com.suixun.service.HomeModuleService;

@Controller
@RequestMapping("/homepage")
public class HomePageManage extends BaseManager {

	@Autowired
	private HomeModuleService homeModuleService;

	@Autowired
	private HomeModuleConfigService homeModuleConfigService;

	@RequestMapping(value = "listHomeModule.json", method = { RequestMethod.GET })
	@ResponseBody
	public Object listHomeModule() {

		return success(homeModuleService.listHomeModule());
	}

	@RequestMapping(value = "saveHomeModule.json", method = { RequestMethod.POST })
	@ResponseBody
	public Object saveHomeModule(@RequestBody HomeModule homeModule) {

		try {
			homeModuleService.save(homeModule);
			return success("操作成功！");
		} catch (Exception e) {
			return fail(e.getMessage());
		}
	}

	@RequestMapping(value = "delHomeModule.json", method = { RequestMethod.POST })
	@ResponseBody
	public Object delHomeModule(Integer id) {

		try {
			homeModuleService.del(id);
			return success("操作成功！");
		} catch (Exception e) {
			return fail(e.getMessage());
		}
	}

	@RequestMapping(value = "updateHomeModule.json", method = { RequestMethod.POST })
	@ResponseBody
	public Object updateHomeModule(@RequestBody HomeModule homeModule) {

		try {
			homeModuleService.update(homeModule);
			return success("操作成功！");
		} catch (Exception e) {
			return fail(e.getMessage());
		}
	}

	@RequestMapping(value = "getHomeModule.json", method = { RequestMethod.GET })
	@ResponseBody
	public Object getHomeModule(Integer id) {

		try {
			return success(homeModuleService.get(id));
		} catch (Exception e) {
			return fail(e.getMessage());
		}
	}

	@RequestMapping(value = "saveHomeModuleConfig.json", method = { RequestMethod.POST })
	@ResponseBody
	public Object saveHomeModuleConfig(@RequestBody List<HomeModuleConfig> list) {

		try {
			homeModuleConfigService.save(list);
			return success("操作成功！");
		} catch (Exception e) {
			return fail(e.getMessage());
		}
	}

	@RequestMapping(value = "delHomeModuleConfigBySchoolid.json", method = { RequestMethod.POST })
	@ResponseBody
	public Object delHomeModuleConfigBySchoolid(Integer schoolId) {

		try {
			homeModuleConfigService.delBySchoolid(schoolId);
			return success("操作成功！");
		} catch (Exception e) {
			return fail(e.getMessage());
		}
	}

	@RequestMapping(value = "delHomeModuleConfig.json", method = { RequestMethod.POST })
	@ResponseBody
	public Object delHomeModuleConfig(Integer id) {

		try {
			homeModuleConfigService.delById(id);
			return success("操作成功！");
		} catch (Exception e) {
			return fail(e.getMessage());
		}
	}

	@RequestMapping(value = "updateHomeModuleConfig.json", method = { RequestMethod.POST })
	@ResponseBody
	public Object updateHomeModuleConfig(@RequestBody List<HomeModuleConfig> list) {

		try {
			homeModuleConfigService.update(list);
			return success("操作成功！");
		} catch (Exception e) {
			return fail(e.getMessage());
		}
	}

	@RequestMapping(value = "listHomeModuleConfigBySchoolId.json", method = { RequestMethod.GET })
	@ResponseBody
	public Object listHomeModuleConfigBySchoolId(Integer schoolId) {

		try {
			return success(homeModuleConfigService.listHomeModuleConfigBySchoolId(schoolId));
		} catch (Exception e) {
			return fail(e.getMessage());
		}
	}
}
